In [1]:
import pandas as pd
import numpy as np

from price import Price
from coin import Coin
import config
import crosscoin
import plot

Price


In [2]:
# Analyze prices of 37 altcoins
prices = [Price(ticker) for ticker in config.ALL_TICKERS]
price_df = crosscoin.create_price_frame(prices, normalize='z_score')

In [3]:
plot.plot_timeseries('Z-Score Normalized Prices', price_df, legend=False)



In [4]:
# Cutoff at later date for better presentation
start = pd.datetime(2013, 8, 25)
price_df_trunc = price_df[start:]
plot.plot_timeseries('Z-Score Normalized Prices', price_df_trunc, legend=False)



In [5]:
# Calculate price correlations
price_corr = price_df.corr()
print price_corr.head()


          ANC       BQC       BTB       BTC        BC       BTE       CNC  \
ANC  1.000000  0.900311  0.832886  0.731201  0.284885  0.905455  0.721316   
BQC  0.900311  1.000000  0.703387  0.606280  0.429885  0.751129  0.776800   
BTB  0.832886  0.703387  1.000000  0.691321  0.251397  0.833870  0.473064   
BTC  0.731201  0.606280  0.691321  1.000000  0.556384  0.611196  0.351828   
BC   0.284885  0.429885  0.251397  0.556384  1.000000  0.056390 -0.034057   

          COL       CGB       DRK    ...          PPC       PXC       XPM  \
ANC  0.810805  0.881792 -0.013289    ...     0.839546  0.826049  0.901160   
BQC  0.734999  0.936048 -0.188529    ...     0.681834  0.788803  0.853653   
BTB  0.819169  0.650470 -0.249392    ...     0.914425  0.564462  0.864366   
BTC  0.680886  0.610707  0.521447    ...     0.850419  0.333633  0.740053   
BC   0.160623  0.414075  0.578883    ...     0.470618  0.474631  0.367234   

          PTS       QRK       TRC       VTC       WDC       YAC       ZET  
ANC  0.907152  0.013346  0.910908  0.852019  0.964351  0.887432  0.660120  
BQC  0.838489  0.007564  0.918456  0.909216  0.879551  0.958406  0.588615  
BTB  0.828394 -0.001893  0.780761  0.883595  0.827819  0.649883  0.548821  
BTC  0.828517  0.097676  0.533576  0.605311  0.668881  0.493715  0.647163  
BC   0.405980  0.176727  0.273501  0.443575  0.249804  0.290342  0.766576  

[5 rows x 37 columns]

In [65]:
# Find any outliers in correlation
print "Mean coefficients (ascending order)"
print "-" * 30
weak = price_corr.mean().order()
print weak.head()


Mean coefficients (ascending order)
------------------------------
DRK    -0.100823
QRK     0.017176
BC      0.307723
DOGE    0.522372
ZET     0.526419
dtype: float64

In [7]:
# Calculate mean of correlation coefficient without outliers
drop = weak[weak < 0.5].index.values

coin_to_coeff = {}
for coin in prices:
    ticker = coin.ticker.upper()
    if ticker in drop:
        continue
    c = price_corr[ticker].drop(ticker)
    for d in drop:
        c = c.drop(d)
    coin_to_coeff[ticker] = c.mean()

top_coeff = pd.Series(coin_to_coeff)
print "Mean coefficients without outliers (descending order)"
print "-" * 30
print top_coeff.order(ascending=False).head(10)


Mean coefficients without outliers (descending order)
------------------------------
MMC    0.881934
VTC    0.845489
MEC    0.838760
XPM    0.834319
ANC    0.828224
PTS    0.826938
WDC    0.817127
NVC    0.812021
BTE    0.802101
NMC    0.797934
dtype: float64

In [54]:
# Calculate BTC correlation
btc_corr = price_corr['BTC'].drop('BTC').drop('DRK').drop('QRK')
print "BTC correlation"
print "-" * 30
print btc_corr.order(ascending=False).head(10)
print "Mean coefficient: {}".format(btc_corr.mean())


BTC correlation
------------------------------
LTC    0.851976
PPC    0.850419
NMC    0.836205
PTS    0.828517
XPM    0.740053
MEC    0.735949
ANC    0.731201
IFC    0.702542
GLD    0.692497
BTB    0.691321
Name: BTC, dtype: float64
Mean coefficient: 0.626915813104

In [58]:
# Calculate LTC correlation
ltc_corr = price_corr['LTC'].drop('LTC').drop('DRK').drop('QRK')
print "LTC correlation"
print "-" * 30
print ltc_corr.order(ascending=False).head(10)
print "Mean coefficient: {}".format(ltc_corr.mean())


LTC correlation
------------------------------
NMC    0.957981
PPC    0.943382
MEC    0.915362
PTS    0.907980
XPM    0.898505
ANC    0.888860
BTB    0.882974
NVC    0.856561
WDC    0.854490
BTC    0.851976
Name: LTC, dtype: float64
Mean coefficient: 0.786609573711

In [36]:
# Graph top 4 coins with highest LTC correlation
ltc_top = ltc_corr.order(ascending=False)[:4]
ltc_tickers = ltc_top.index.tolist()
ltc_tickers.insert(0, 'LTC')
ltc_coins = filter(lambda x : x.ticker in ltc_tickers, prices)
ltc_df = crosscoin.create_price_frame(ltc_coins, normalize='z_score')
start = ltc_df.index.searchsorted(pd.datetime(2013, 10, 1))
plot.plot_timeseries('Z-Score Normalized Prices', ltc_df[start:])
print "Mean coefficient: {}".format(ltc_top.mean())


Mean coefficient: 0.93117631267

In [33]:
# Find the two coins that are most highly correlated

corr = price_corr
# Remove correlation between a coin and itself
for col in corr.columns:
    corr[col] = corr[col].drop(col)
top_two = price_corr.max().order(ascending=False).head(2).index.tolist()
top_coins = filter(lambda x : x.ticker in top_two, prices)
frame = crosscoin.create_price_frame(top_coins, normalize='z_score')
start = frame.index.searchsorted(pd.datetime(2013, 10, 1))
frame = frame[start:]
plot.plot_timeseries('Z-Score Normalized Prices', frame)
print "Corr coefficient: {}".format(price_corr[top_two[0]][top_two[1]])


Mean coefficient: 0.979682108923

In [63]:
big = ['LTC', 'BTC']
big_coins = filter(lambda x : x.ticker in big, prices)
frame = crosscoin.create_price_frame(big_coins, normalize='z_score')
start = frame.index.searchsorted(pd.datetime(2013, 10, 1))
frame = frame.fillna(method='pad')
frame = frame[start:]
plot.plot_timeseries('Z-Score Normalized Prices', frame)
print "Corr coefficient: {}".format(price_corr[big[0]][big[1]])


Corr coefficient: 0.851975627033

In [83]:
big = ['DRK', 'BTC']
big_coins = [Price(ticker) for ticker in big]
frame = crosscoin.create_price_frame(big_coins, normalize='z_score')
start = frame.index.searchsorted(pd.datetime(2014, 4, 1))
frame = frame.fillna(method='pad')
frame = frame[start:]
plot.plot_timeseries('Z-Score Normalized Prices', frame)
print "Corr coefficient: {}".format(price_corr[big[0]][big[1]])


Corr coefficient: 0.521447279491

In [12]:
# Let's remove all the coins that are below the average coefficient
mean_coeff = price_corr.mean().mean()
good_tickers = []
for ticker in price_corr:
    if price_corr[ticker].mean() >= mean_coeff:
        good_tickers.append(ticker)

# We now have a set of coins that should correlate very strongly
good_price_df = price_df[good_tickers]
corr = good_price_df.corr()
# NOTE: BTC is not in this list!
# Remove correlation between a coin and itself
for col in corr.columns:
    corr[col] = corr[col].drop(col)
good_mean_corr = corr.mean().mean()
print 'Subset of', len(good_tickers), 'coins exists with mean correlation:', good_mean_corr

for ticker in good_tickers:
    print ticker,


Subset of 27 coins exists with mean correlation: 0.833145890733
ANC BQC BTB BTE COL CGB DGC FTC FLO FRK FRC GLD LTC LKY MEC MMC MNC NMC NVC PPC PXC XPM PTS TRC VTC WDC YAC

Difficulty


In [43]:
# Load all data for a subset of altcoins
coins = [Coin(ticker) for ticker in config.TICKERS]
btc = Coin('btc')
coins.append(btc)
(ppc, dgc, mec, anc, nvc, nmc, mnc, gld, ftc, ltc, drk, lky, btc) = coins

In [21]:
# Analyze difficulty
diff_df = crosscoin.create_coin_frame(coins, 'block_chain_work', normalize='z_score')

In [79]:
diff_corr = diff_df.corr()
print diff_corr.head()


          ppc       dgc       mec       anc       nvc       nmc       mnc  \
ppc  1.000000  0.249523  0.244951  0.189050 -0.030509  0.181255  0.136462   
dgc  0.249523  1.000000  0.195953  0.190739  0.064373  0.124167  0.059981   
mec  0.244951  0.195953  1.000000  0.816032  0.153878  0.893383  0.393133   
anc  0.189050  0.190739  0.816032  1.000000  0.078366  0.841973  0.385134   
nvc -0.030509  0.064373  0.153878  0.078366  1.000000  0.127147  0.160293   

          gld       ftc       ltc       drk       lky       btc  
ppc  0.228144 -0.009992  0.283241  0.139479  0.147459  0.263597  
dgc  0.201674 -0.093269  0.865147  0.343144  0.071927  0.134901  
mec  0.797774 -0.123135  0.891154  0.451962  0.572475  0.905812  
anc  0.730611  0.015198  0.775336  0.343883  0.502773  0.516643  
nvc  0.148222  0.087626  0.150411  0.070622  0.082285 -0.076382  

In [41]:
# Plot difficulty
# Need to pad before graphing to fill in NA values; otherwise, smoothing breaks
diff_df_padded = diff_df.fillna(method='pad')
plot.plot_timeseries('Z-Score Normalized, Smoothed Work', diff_df_padded, window=10000)



In [80]:
# Show difficulty correlation with BTC
print "Difficulty correlation with BTC"
print "-" * 30
btc_corr = diff_corr['btc'].drop('btc').order(ascending=False)
print btc_corr


Difficulty correlation with BTC
------------------------------
ltc    0.991027
nmc    0.987594
gld    0.950476
mec    0.905812
drk    0.571246
anc    0.516643
lky    0.455177
mnc    0.392463
ppc    0.263597
dgc    0.134901
ftc   -0.042568
nvc   -0.076382
Name: btc, dtype: float64

In [39]:
# Graph top 4 coins with highest BTC difficulty correlation
btc_top = btc_corr.order(ascending=False)[:5]
btc_tickers = btc_top.index.tolist()
btc_df = diff_df[btc_tickers]
btc_coins = filter(lambda x : x.ticker in btc_tickers, coins)
btc_df = crosscoin.create_coin_frame(btc_coins, 'block_chain_work', normalize='z_score')

# Need to pad before graphing to fill in NA values; otherwise, smoothing breaks
btc_df_padded = btc_df.fillna(method='pad')
start = btc_df_padded.index.searchsorted(pd.datetime(2013, 10, 1))
end = btc_df_padded.index.searchsorted(pd.datetime(2014, 12, 30))
plot.plot_timeseries('Z-Score Normalized, Smoothed Work', btc_df_padded[start:end], window=10000)
print "Mean coefficient: {}".format(btc_top.mean())


Mean coefficient: 0.966981574875

Number of transactions


In [42]:
# Analyze number of transactions
tx_df = crosscoin.create_coin_frame(coins, 'block_num_tx', normalize='z_score')
tx_df_padded = tx_df.fillna(method='pad')
plot.plot_timeseries('Z-Score Normalized, Smoothed Tx. Volume', tx_df_padded, window=10000)


          ppc       dgc       mec       anc       nvc       nmc       mnc  \
ppc       NaN  0.027902  0.016950  0.002022  0.002231 -0.002007  0.017495   
dgc  0.027902       NaN  0.017169 -0.000168 -0.005539  0.000007  0.028014   
mec  0.016950  0.017169       NaN  0.012700  0.021389 -0.011555  0.022536   
anc  0.002022 -0.000168  0.012700       NaN  0.013477  0.006621 -0.001315   
nvc  0.002231 -0.005539  0.021389  0.013477       NaN -0.008534 -0.001234   
nmc -0.002007  0.000007 -0.011555  0.006621 -0.008534       NaN  0.000924   
mnc  0.017495  0.028014  0.022536 -0.001315 -0.001234  0.000924       NaN   
gld  0.011776  0.014202 -0.010106 -0.010902 -0.016236 -0.014885  0.001638   
ftc  0.031448  0.011743  0.011488 -0.008816 -0.003737 -0.001015  0.029377   
ltc  0.066764  0.045906  0.014224 -0.000641 -0.012494  0.020516  0.059032   
drk  0.019165  0.019562  0.005095 -0.009299 -0.061048  0.006167  0.012975   
lky  0.025642  0.020112  0.048937  0.016549  0.015794 -0.009176  0.027566   
btc  0.003090 -0.006917 -0.010943  0.009140  0.002814  0.047940  0.018400   

          gld       ftc       ltc       drk       lky       btc  
ppc  0.011776  0.031448  0.066764  0.019165  0.025642  0.003090  
dgc  0.014202  0.011743  0.045906  0.019562  0.020112 -0.006917  
mec -0.010106  0.011488  0.014224  0.005095  0.048937 -0.010943  
anc -0.010902 -0.008816 -0.000641 -0.009299  0.016549  0.009140  
nvc -0.016236 -0.003737 -0.012494 -0.061048  0.015794  0.002814  
nmc -0.014885 -0.001015  0.020516  0.006167 -0.009176  0.047940  
mnc  0.001638  0.029377  0.059032  0.012975  0.027566  0.018400  
gld       NaN  0.075819  0.020613  0.009471  0.016426 -0.036764  
ftc  0.075819       NaN  0.061887  0.034523  0.026447 -0.019321  
ltc  0.020613  0.061887       NaN  0.048344  0.019283  0.032427  
drk  0.009471  0.034523  0.048344       NaN  0.023971 -0.021712  
lky  0.016426  0.026447  0.019283  0.023971       NaN -0.038949  
btc -0.036764 -0.019321  0.032427 -0.021712 -0.038949       NaN  

In [46]:
tx_df = crosscoin.create_coin_frame(coins, 'block_num_tx', normalize='z_score')
corr = tx_df.corr()
print corr


          ppc       dgc       mec       anc       nvc       nmc       mnc  \
ppc  1.000000  0.025241  0.020058  0.061888  0.010713  0.033279  0.010110   
dgc  0.025241  1.000000  0.018182 -0.000590 -0.004877 -0.010531  0.009667   
mec  0.020058  0.018182  1.000000  0.039438  0.015622 -0.031177  0.001747   
anc  0.061888 -0.000590  0.039438  1.000000 -0.017963  0.040511  0.017564   
nvc  0.010713 -0.004877  0.015622 -0.017963  1.000000  0.008147 -0.029303   
nmc  0.033279 -0.010531 -0.031177  0.040511  0.008147  1.000000 -0.015313   
mnc  0.010110  0.009667  0.001747  0.017564 -0.029303 -0.015313  1.000000   
gld  0.107386 -0.003248 -0.009622 -0.008545 -0.003694 -0.030978 -0.038050   
ftc  0.060821  0.068334 -0.010402 -0.017791  0.013913 -0.007146  0.075097   
ltc  0.105239  0.032832  0.030228  0.052608  0.091606  0.060106  0.046483   
drk  0.165380 -0.015334  0.065120 -0.004935  0.018492 -0.032499 -0.031847   
lky  0.054885  0.025076  0.026253 -0.001328  0.019801 -0.034064  0.041275   
btc -0.055569 -0.017142 -0.012616  0.012604 -0.121580  0.110335 -0.019822   

          gld       ftc       ltc       drk       lky       btc  
ppc  0.107386  0.060821  0.105239  0.165380  0.054885 -0.055569  
dgc -0.003248  0.068334  0.032832 -0.015334  0.025076 -0.017142  
mec -0.009622 -0.010402  0.030228  0.065120  0.026253 -0.012616  
anc -0.008545 -0.017791  0.052608 -0.004935 -0.001328  0.012604  
nvc -0.003694  0.013913  0.091606  0.018492  0.019801 -0.121580  
nmc -0.030978 -0.007146  0.060106 -0.032499 -0.034064  0.110335  
mnc -0.038050  0.075097  0.046483 -0.031847  0.041275 -0.019822  
gld  1.000000  0.035611  0.058440 -0.014007  0.026948  0.071317  
ftc  0.035611  1.000000  0.025272  0.042619  0.063650 -0.048126  
ltc  0.058440  0.025272  1.000000 -0.000867  0.062200  0.139231  
drk -0.014007  0.042619 -0.000867  1.000000 -0.002775  0.006024  
lky  0.026948  0.063650  0.062200 -0.002775  1.000000 -0.029173  
btc  0.071317 -0.048126  0.139231  0.006024 -0.029173  1.000000  

In [ ]: